namespace MIMSDomain.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class NewMigration : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Patients",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(),
                        FirstName = c.String(nullable: false),
                        MiddleName = c.String(),
                        LastName = c.String(),
                        PatientType = c.Short(nullable: false),
                        Sex = c.String(),
                        Phone = c.String(),
                        Email = c.String(),
                        Address = c.String(),
                        Age = c.Int(),
                        DateOfBirth = c.DateTime(nullable: false),
                        HivStatus = c.Boolean(nullable: false),
                        NextofKinRelationType = c.Int(nullable: false),
                        Occupation_Id = c.Int(),
                        Religion_Id = c.Int(),
                        Tribe_Id = c.Int(),
                        Genotype_Id = c.Int(),
                        BloodGroup_Id = c.Int(),
                        NextOfKin_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Occupations", t => t.Occupation_Id)
                .ForeignKey("dbo.Religions", t => t.Religion_Id)
                .ForeignKey("dbo.Tribes", t => t.Tribe_Id)
                .ForeignKey("dbo.Genotypes", t => t.Genotype_Id)
                .ForeignKey("dbo.BloodGroups", t => t.BloodGroup_Id)
                .ForeignKey("dbo.NextOfKins", t => t.NextOfKin_Id)
                .Index(t => t.Occupation_Id)
                .Index(t => t.Religion_Id)
                .Index(t => t.Tribe_Id)
                .Index(t => t.Genotype_Id)
                .Index(t => t.BloodGroup_Id)
                .Index(t => t.NextOfKin_Id);
            
            CreateTable(
                "dbo.Occupations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Religions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Tribes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Genotypes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.BloodGroups",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.NextOfKins",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(),
                        MiddleName = c.String(),
                        LastName = c.String(),
                        Phone = c.String(),
                        Email = c.String(),
                        Address = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Allergies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        AllergyType = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.MedicalPersonnels",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(),
                        FirstName = c.String(),
                        MiddleName = c.String(),
                        LastName = c.String(),
                        Sex = c.String(),
                        MedicalPersonnelType = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.MedicalFacilities",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(),
                        Name = c.String(),
                        MedicalFacilityType = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SurgicalHistories",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        SurgeryDetails = c.String(),
                        Narrative = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.ObstetricHistories",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        Narrative = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Patients", new[] { "NextOfKin_Id" });
            DropIndex("dbo.Patients", new[] { "BloodGroup_Id" });
            DropIndex("dbo.Patients", new[] { "Genotype_Id" });
            DropIndex("dbo.Patients", new[] { "Tribe_Id" });
            DropIndex("dbo.Patients", new[] { "Religion_Id" });
            DropIndex("dbo.Patients", new[] { "Occupation_Id" });
            DropForeignKey("dbo.Patients", "NextOfKin_Id", "dbo.NextOfKins");
            DropForeignKey("dbo.Patients", "BloodGroup_Id", "dbo.BloodGroups");
            DropForeignKey("dbo.Patients", "Genotype_Id", "dbo.Genotypes");
            DropForeignKey("dbo.Patients", "Tribe_Id", "dbo.Tribes");
            DropForeignKey("dbo.Patients", "Religion_Id", "dbo.Religions");
            DropForeignKey("dbo.Patients", "Occupation_Id", "dbo.Occupations");
            DropTable("dbo.ObstetricHistories");
            DropTable("dbo.SurgicalHistories");
            DropTable("dbo.MedicalFacilities");
            DropTable("dbo.MedicalPersonnels");
            DropTable("dbo.Allergies");
            DropTable("dbo.NextOfKins");
            DropTable("dbo.BloodGroups");
            DropTable("dbo.Genotypes");
            DropTable("dbo.Tribes");
            DropTable("dbo.Religions");
            DropTable("dbo.Occupations");
            DropTable("dbo.Patients");
        }
    }
}
